package com.ynny.h14.Service.Impl;

import com.ynny.h14.Entity.R;
import com.ynny.h14.Entity.Users;
import com.ynny.h14.Mapper.UsersMapper;
import com.ynny.h14.Service.UsersService;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class UsersServiceImpl implements UsersService {
    @Autowired
    private UsersMapper usersMapper;
    @Override
    public List<Users> findAll(Users users) {
        return usersMapper.selectAll(users);
    }

    @Override
    public R login(Users users) {
        if (users.getNumber()==null||users.getPassword()==null){
            return R.error(411,"用户名或密码为空");//用户名或密码为空
        }else {
            Users  users1=new Users();
            users1.setNumber(users.getNumber());
            Users users2 = usersMapper.selectByOne(users1);
            if (users2==null){
                return R.error(412,"用户不存在");//用户不存在
            }else {//用户存在
                if (users2.getPassword().equals(users.getPassword())){
                    users2.setPassword(null);//密码应该不可见
                    return R.ok(users2);//密码正确
                }else {
                    return R.error(413,"密码错误");//密码错误
                }
            }
        }

    }
}
